#set( $layout = "layout/blank.vm" )
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>测试</title>
    <link rel="stylesheet" type="text/css" href="$!{request.getContextPath()}/res/css/bootstrap/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="$!{request.getContextPath()}/res/css/manage.css"/>
    <script type="text/javascript" src="$!{request.getContextPath()}/res/js/jquery.js"></script>
    <script src="$!{request.getContextPath()}/res/js/highcharts.js"></script>
    <script type="text/javascript" src="$!{request.getContextPath()}/res/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="$!{request.getContextPath()}/res/js/WdatePicker.js"></script>

</head>
<body>
<div>
    <#list model.properties as property>
        <#if property.columnName!=id_col>
          ${property.propertyName}:<input type="text" value="" id="${property.propertyName}"/><br/>
        <#else>
          主键${property.propertyName}:<input type="text" value="" id="${property.propertyName}"/><br/>(更新或者删除的时候需要填写)
        </#if>
    </#list>
</div>


<div>
    <a id="save" href="javascript:;">保存</a>&nbsp;
    <a id="update" href="javascript:;">更新</a>&nbsp;
    <a id="delete" href="javascript:;">删除</a>&nbsp;
</div>

<script type="text/javascript">
    $(function(){
        <!--saveS-->
        $("#save").click(function(){
        <#list model.properties as property>
            <#if property.columnName!=id_col>var ${property.propertyName} = $("#${property.propertyName}").val();</#if>
        </#list>
            $.ajax({
                type:'post',
                url:'insert.do',
                data:{
                    <#assign size=model.properties?size/>
                    <#assign first = 0/>
                    <#assign total = 0/>
                    <#list model.properties as property><#if property.columnName!=id_col><#if first!=0 && total!=size>,</#if>${property.propertyName}:${property.propertyName}<#assign first = 1/></#if><#assign total = total+1/></#list>
                }
                success:function (data){
                    alert("SUCCESS TODO")
                },
                error:function(data){
                    alert("ERROR TODO")
                    return false;
                }
            })
        });
        <!--saveS-->

        <!--updateS-->
        $("#update").click(function(){
        <#list model.properties as property>
            var ${property.propertyName} = $("#${property.propertyName}").val();
        </#list>
            $.ajax({
                type:'post',
                url:'update.do',
                data:{
                   <#assign size=model.properties?size/>
                   <#assign first = 0/>
                   <#assign total = 0/>
                   <#list model.properties as property><#if first!=0 && total!=size>,</#if>${property.propertyName}:${property.propertyName}<#assign first = 1/><#assign total = total+1/></#list>
                }
                success:function (data){
                    alert("SUCCESS TODO")
                },
                error:function(data){
                    alert("ERROR TODO")
                    return false;
                }
            })
        });
        <!--updateE-->

        <!--deleteS-->
        $("#delete").click(function(){
            <#list model.properties as property><#if property.columnName==id_col>var ${property.propertyName}=$("#${property.propertyName}").val();</#if></#list>
            $.ajax({
              type:'post',
              url:'delete.do',
              data:{
                <#list model.properties as property><#if property.columnName==id_col>${property.propertyName}:${property.propertyName}</#if></#list>
              }
              success:function (data){
                 alert("SUCCESS TODO")
              },
              error:function(data){
                 alert("ERROR TODO")
                 return false;
              }
            })
        });
        <!--deleteE-->



    })
</script>



</body>
</html>